package xyz.xiangyushui.dao.connectionFactory;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class JNDIConnectionFactory implements DBConnectoryFactory{
	private static DataSource ds;
	 
	 static{
		Context ctx;
		try {
			ctx = new InitialContext();
			ds=(DataSource)ctx.lookup("java:comp/env/jdbc/desserthouse");
		} catch (NamingException e) {
			e.printStackTrace();
		}
		
	}
	
	public  Connection getConnection() {
		Connection c = null;
		try {
			c = ds.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return c;
	}
}
